package tmall.bean;

/**
 * The class describes Tmall's users.
 * @author Harry Chou
 * @date 2019/3/3
 */
public class User {
    private String password;
    private String name;
    private int id;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    /**
     * Generates the anonymous users' names in comments page.
     * @return anonymous names
     */
    public String getAnonymousName(){
        if(null==name) {
            return null;
        }

        if(name.length()<=1) {
            return "*";
        }

        if(name.length()== 2) {
            return name.substring(0,1) +"*";
        }

        char[] cs =name.toCharArray();
        for (int i = 1; i < cs.length-1; i++) {
            cs[i]='*';
        }
        return new String(cs);
    }
}
